package br.com.sgpv2.hibernate.impostorenda;

import java.util.Collections;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import br.com.sgpv2.entity.impostorenda.ImpostoRenda;
import br.com.sgpv2.hibernate.infra.SGPGenericDAO;

public class ImpostoRendaHibernateDAO extends SGPGenericDAO<ImpostoRenda>
		implements ImpostoRendaRepository {

	private static final String TODOS = "Todos";

	/** Construtor padrão. */
	@Autowired
	public ImpostoRendaHibernateDAO(
			@Qualifier("sessionFactory") SessionFactory factory) {
		super(ImpostoRenda.class);
		super.setSessionFactory(factory);
	}

	/** {@inheritDoc} */
	@Override
	public List<ImpostoRenda> consultarPorMesAno(String mes, String ano) {
		Criteria criteria = createCriteria(ImpostoRenda.class);
		if (mes != null && !TODOS.equals(mes)) {
			criteria.add(Restrictions.eq("mesReferencia", mes));
		}
		if (ano != null && !TODOS.equals(ano)) {
			criteria.add(Restrictions.eq("anoReferencia", ano));
		}
		return Collections.checkedList((List<ImpostoRenda>) criteria.list(),
				ImpostoRenda.class);
	}
}
